package org.flyframework.command
{
	import mx.collections.ArrayCollection;
	
	
	public class CommandStack
	{
		
		public var commands:ArrayCollection = new ArrayCollection();
		
		
		//--------------------------------------------------------------------------
		// Init
		//--------------------------------------------------------------------------
		
		public function CommandStack()
		{
			
		}
		
		
		//--------------------------------------------------------------------------
		// Public
		//--------------------------------------------------------------------------
		
		public function peek():ICommand
		{
			if( empty ) return null;
			return ICommand(this.commands.getItemAt(0));
		}
		
		public function pop():ICommand
		{
			if( empty ) return null;
			return ICommand(this.commands.removeItemAt(0));
		}
		
		public function push( cmd:ICommand ):void
		{
			this.commands.addItemAt(cmd, 0);
		}
		
		
		public function get empty():Boolean
		{
			return( this.commands.length == 0 );
		}
		
		
		public function size():int
		{
			return this.commands.length;
		}
		
		public function trim( size:int ):void
		{
			if( size < 0 ) return;
			
			while( this.commands.length > size )
			{
				// remove last
				this.commands.removeItemAt(this.commands.length-1);
			}
		}
		
		public function removeAll():void
		{
			this.commands.removeAll();
		}
		

	}
}